﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using ZCustomControl.Helpers;

namespace ZCustomControl.Converters
{
    public class TreeViewItemDepthToThicknessConverter : IValueConverter
    {
        public TreeViewItemDepthToThicknessConverter()
        {
            Indent = 28;
            MarginLeft = 20;
        }

        /// <summary>
        /// 获取或设置缩进的像素个数。
        /// </summary>
        public double Indent { get; set; }

        /// <summary>
        /// 获取或设置初始的左边距。
        /// </summary>
        public double MarginLeft { get; set; }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            TreeViewItem item = value as TreeViewItem;
            if (item == null)
            {
                return new Thickness(0);
            }
            int rate = LVTreeHelper.GetDepth<TreeViewItem>(item);
            return new Thickness(this.MarginLeft + this.Indent * rate, 0, 10, 0);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
